<template>
  <view>
    <u-modal 
      :show="show" 
      title="投票成功" 
      :content="modalContent"
      confirmText="确定"
      :showCancelButton="false"
      @confirm="handleConfirm"
      @close="handleClose"
    >
      <view class="modal-content">
        <view class="success-text">
          您已完成了<span class="vote-name">{{ voteName || '该' }}</span>投票如果对投票结果有疑问请拨打
        </view>
        <view class="phone-number">
          <text class="phone-text"  @click="makePhoneCall">{{companyInfo.phone}}</text>
        </view>
        <view class="contact-text">客服咨询</view>
      </view>
    </u-modal>
  </view>
</template>

<script>
import companyInfo from '@/util/companyInfo'
export default {
  name: 'VoteSuccessModal',
  props: {
  
    voteName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      modalContent: '',
      show:false,
      companyInfo
    }
  },
  watch: {
    show(newVal) {
      if (newVal) {
        this.modalContent = `您已完成了${this.voteName || '该'}投票，如果对投票结果有疑问请拨打 40005393400 客服咨询`
      }
    }
  },
  methods: {
    // 显示弹框
    showModal() {
      this.show = true
    },
    
    // 隐藏弹框
    hideModal() {
      this.show = false
    },
    
    // 拨打电话
    makePhoneCall() {
      uni.makePhoneCall({
        phoneNumber: '40005393400',
        success: (res) => {
          console.log('拨打电话成功')
        },
        fail: (err) => {
          console.log('拨打电话失败', err)
          // 如果拨打失败，显示提示
          
        }
      })
    },
    
    // 确认按钮点击
    handleConfirm() {
      this.hideModal()
      this.$emit('confirm')
    },
    
    // 关闭弹框
    handleClose() {
      this.hideModal()
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>
.modal-content {
  padding: 20rpx 0;
  text-align: center;
}

.success-text {
  font-size: 32rpx;
  color: #333;
  margin-bottom: 20rpx;
  font-weight: 500;
}

.contact-text {
  font-size: 28rpx;
  color: #666;
  margin-bottom: 10rpx;
}

.phone-number {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20rpx 0;
  padding: 20rpx;
  background-color: #f8f9fa;
  border-radius: 12rpx;
  cursor: pointer;
}

.phone-text {
  font-size: 32rpx;
  color: $uni-color-primary;
  font-weight: 600;
  margin-left: 10rpx;
  text-decoration: underline;
}
.vote-name{
  color: $uni-color-primary;
}

.phone-number:active {
  background-color: #e3f2fd;
}
</style>
